<% remote_form_for :project, @project, :url => polymorphic_path([:admin, @project]), :update => :project, :html => {:class => "remote_form", :id => "project_form", :method => @project.new_record? ? :post : :put } do |f| %>
  <fieldset>
    <legend>Project Info</legend>
    <div class="form_group">   
      <div class="form_pair">
        <%= f.label :title %>
        <%= f.text_field :title, :class => "span-16" %>
      </div>
    
      <div class="form_pair">
        <%= f.label :location %>
        <%= f.text_field :location, :class => "span-6" %>
      </div>
    </div>
    
    <div class="form_group">   
      <div class="form_pair">
        <%= f.label :total_amount, "Total Project Amount" %>
        <span class="large">$</span> <%= f.text_field :total_amount, :class => "span-8" %>
      </div>
    </div>
  
    <div class="form_group">   
      <div class="form_pair span-5">
        <%= f.label :started_on %>
        <%= f.text_field :started_on, :id => "project_started_on_date_picker", :class => "date_picker", :value => @project.started_on.blank? ? "" : @project.started_on.to_s(:numeric) %>
      </div>
    
      <div class="radio_group span-5">
        <p>Is this Project Completed?</p>
        <div class="form_radio">
          <label for="control[project_complete]"><%= radio_button("control", "project_complete", "no", {:checked => @project.completed_on.blank?}) %> No</label>
        </div>
    
        <div class="form_radio">
          <label for="control[project_complete]"><%= radio_button("control", "project_complete", "yes", {:checked => !@project.completed_on.blank?}) %> Yes</label>
        </div>
      </div>
    
      <div class="form_pair span-5 last" id="project_completed_on_box" style="display:<%= @project.completed_on.blank? ? "none" : "block" %>;">
        <%= f.label :completed_on %>
        <%= f.text_field :completed_on, :id => "project_completed_on_date_picker", :class => "date_picker", :value => @project.completed_on.blank? ? "" : @project.completed_on.to_s(:numeric) %>
      </div>     
    </div>
    <div class="form_group clear">
      <div class="form_pair">
        <label for="project_description_markdown">Description <span class="quiet">(uses Markdown)</span></label>
        <%= f.text_area :description_markdown, :class => "markdown_support" %>
        <p><%= link_to_function "Preview", "toggle_markdown_preview('project_description_markdown')" %> | <%= link_to "What the hell is Markdown?", "http://daringfireball.net/projects/markdown/syntax" %></p>
        <div class="markdown_help">
          <div id="preview_project_description_markdown" class="markdown_preview hidden"></div>
        </div>
      </div>
    </div>
  
    <div class="form_group">   
      <div class="form_pair">
        <%= f.label :tags %>
        <%= f.text_field :tags, :class => "span-16", :value => project.tags.collect{|t| t.stub_name + " "} %>
        <p class="quiet small">Separated with a space. For multiple word tags, use a dash like <strong>multiple-words.</strong></p>
      </div>
    </div>
  
    <div class="buttons">
      <%= f.submit %> or <%= link_to_remote "Cancel", :update => "project", :url => admin_project_path(project), :method => :get %>
    </div>
  </fieldset>
<% end %>

<script type="text/javascript">
  $j( "#project_started_on_date_picker" ).datepicker({ nextText: '&rarr;', prevText: '&larr;' });
  $j( "#project_completed_on_date_picker" ).datepicker({ nextText: '&rarr;', prevText: '&larr;' });
    
  $j("#control_project_complete_no").bind( "click", function() {$j("#project_completed_on_box").fadeOut()});
  $j("#control_project_complete_yes").bind("click", function() {$j("#project_completed_on_box").fadeIn()});
  
  $j("#project_description_markdown").bind("keyup",function() {
    var preview_element   = $j("#preview_" + this.id);
    if ( !preview_element.hasClass("hidden") ){
      preview_markdown(this.id);
    }
  });
</script>

